import DEFINE = require('./../../common/DEFINE');
import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Serializer = require('./Serializer');
var CONFIG=require('../../../../common/config');
export  = SJGPageDescribe;

/**
 *
 * @author 
 *
 */
class SJGPageDescribe extends Serializer{
    public index = 0;
    public id = 0;
    public play_time = 1;
    public show_style = 0;
    public disappear_style = 0;
    public audio: Array<number> = new Array<number>();
    public video: Array<number> = new Array<number>();
    /**
     * 保留flg: 0普通页，1保留页
     */ 
    public backup_flg = 0;
    // DB用,不序列化
    public page_id = 0;
    public base_page_id = 0;
    
	public constructor() {
        super();
        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_SJGPageDescribe;
	}
	
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj, versionId) { 
        super.fromJson( jsonObj, versionId );
        
        this.index = jsonObj.index;
        this.id = jsonObj.id;
        this.play_time = jsonObj.play_time;
        this.show_style = jsonObj.show_style;
        this.disappear_style = jsonObj.disappear_style;   
        if (jsonObj.audio){ 
            var len = jsonObj.audio.length;
            for ( var i = 0; i < len;i++){
                this.audio.push( jsonObj.audio[i] );
            }
        }
        if (jsonObj.video){ 
            var len = jsonObj.video.length;
            for ( var i = 0; i < len;i++){
                this.video.push( jsonObj.video[i] );
            }
        }
        if(jsonObj.hasOwnProperty('backup_flg')) {
            this.backup_flg = jsonObj.backup_flg;
        } else {
            this.backup_flg = 0;
        }
    }
    // 转成json字符串
    public toJson():string {                                                                      
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length-2);
                        
        var ret = '{';
            ret +=superJson;   
                        
            // index
            ret +=',';
            ret += '"index":';
            ret += this.index;
                    
            // id
            ret +=',';
            ret += '"id":';
            ret += this.id;
            
            // play_time
            ret +=',';
            ret += '"play_time":';
            ret += this.play_time;
            
            // show_style
            ret +=',';
            ret += '"show_style":';
            ret += this.show_style;
            
            // disappear_style
            ret +=',';
            ret += '"disappear_style":';
            ret += this.disappear_style;
            
            // audio
            if (this.audio.length>0){
                ret +=',';
                ret += '"audio":[';
                for ( var i = 0; i < this.audio.length;i++){
                    if ( i > 0 ) { 
                            ret +=',';
                    }
                    ret += this.audio[i];
                }  
                ret += ']';
            }
            
            // video
            if (this.video.length>0){
                ret +=',';
                ret += '"video":[';
                for ( var i = 0; i < this.video.length;i++){
                    if ( i > 0 ) { 
                        ret +=',';
                    }
                    ret += this.video[i];
                }  
                ret += ']';
            }
            
            // backup_flg
            ret += ',';
            ret += '"backup_flg":';
            ret += this.backup_flg;
                                                                                                                                            
            ret+='}';
            return ret;
        }   
//SJG_MARK_APPEND--------------------


}//SJG_MARK_END-------------------------